package com.icinfo.cloud.provider.common.utils;

import com.alibaba.fastjson.JSONObject;
import com.icinfo.framework.tools.utils.Md5Utils;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * 描述：消息服务工具类
 *
 * @author tianrunjia
 * @date 2022-08-16
 */
@Slf4j
public class SMSUtils {

    /**
     * 全省短信发送
     *
     * @param mobile 手机号、content 短信内容、messageid 短信id
     * @date 2022-08-16
     * @author tianrunjia
     * @throws Exception
     */
    public static String sendTextMessage(String mobile, String content,String messageid) throws Exception {
        /*String servercode = "ZxF1Wzfp"; //业务代码
        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));//消息发送时间
        String serverpwd = "VeIl4JyX";//接入密码
        String sign = Md5Utils.md5(servercode + serverpwd + time); //servercode+serverpwd+time
        String srcnum = "3313";//短号
        String desttype = "0";//0:对方接收手机号码     1：对方登录名
        String requestURL = "http://10.145.147.112:8581/proxy/dxfwAddr/servlet/smsapi?method=send";
        Map<String, Object> paraM = new HashMap<String, Object>();
        paraM.put("servercode", servercode);
        paraM.put("time", time);
        paraM.put("sign",sign);
        paraM.put("srcnum", srcnum);
        paraM.put("desttype", desttype);
        paraM.put("dest", mobile);
        paraM.put("message", content);
        paraM.put("messageid", messageid);*/

        //String exceptionMsg = "发送信息异常";
        String requestURL = "http://23.30.240.108:8199/jeecg-boot/sms/OrgSend";
        System.out.println("-----短信接口调用开始-----");
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("username","zhzf");
        jsonObject.put("password","Cq123456?");
        jsonObject.put("msg",content);
        jsonObject.put("phone",mobile);
        String result = HttpUtils.doPostJson(requestURL,jsonObject.toJSONString());
        System.out.println("--返回结果:"+result);
        System.out.println("-----短信接口调用结束-----");
        return result;
    }

    public static void main(String[] args) throws Exception {
        sendTextMessage("18868876270","测试","");
    }
}
